---
title: PullRequests generator
hide_title: true
---

import TierLabel from "../_components/TierLabel";

# PullRequests generator <TierLabel tiers="enterprise" />

The `pullRequests` generator will query a repository for open pull requests and emit a set of parameters for each pull request.

### Example

```yaml
apiVersion: templates.weave.works/v1alpha1
kind: GitOpsSet
metadata:
  name: pull-requests-sample
spec:
  generators:
    - pullRequests:
        interval: 5m
        driver: github
        repo: bigkevmcd/go-demo
        secretRef:
          name: github-secret
  templates:
    - content:
        apiVersion: source.toolkit.fluxcd.io/v1beta2
        kind: GitRepository
        metadata:
          name: "pr-{{ .element.number }}-gitrepository"
          namespace: default
        spec:
          interval: 5m0s
          url: "{{ .element.clone_url }}"
          ref:
            branch: "{{ .element.branch }}"
    - content:
        apiVersion: kustomize.toolkit.fluxcd.io/v1beta2
        kind: Kustomization
        metadata:
          name: "pr-{{ .element.number }}-demo"
          namespace: default
        spec:
          interval: 5m
          path: "./examples/kustomize/environments/dev"
          prune: true
          targetNamespace: "{{ .element.branch }}-ns"
          sourceRef:
            kind: GitRepository
            name: "pr-{{ .element.number }}-gitrepository"
```
This example will poll "github.com/bigkevmcd/go-demo" for open pull requests and trigger the deployment of these by creating a Flux `GitRepository` and `Kustomization` to deploy.

As the generator only queries open pull requests, when a PR is closed, the generated resources will be removed.

For non-public installations, you can configure the `serverURL` field and point it to your own installation.

The `driver` field can be `github` or `gitlab` or `bitbucketserver`, other options can be supported from [go-scm](https://github.com/jenkins-x/go-scm/blob/main/scm/factory/factory.go).

Additionally labels can be provided for querying pull requests with matching labels e.g.
```yaml
- pullRequests:
    interval: 5m
    driver: github
    repo: bigkevmcd/go-demo
    secretRef:
      name: github-secret
    labels:
      - deploy
```

The fields emitted by the pull-request are as follows:

 * `number` this is generated as a string representation
 * `branch` this is the source branch
 * `head_sha` this is the SHA of the commit in the merge branch
 * `clone_url` this is the HTTPS clone URL for this repository
 * `clone_ssh_url` this is the SSH clone URL for this repository

You will need an API key that can query the GitHub API.
```shell
$ kubectl create secret generic github-secret \
  --from-literal password=<insert access token here>
```
You can limit the scope of this token to read only access to your repositories.

import RBACWarning from './_rbac_warning.mdx';

<RBACWarning />